package com.ruoyi.web.pojo.dto.devicedata;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.CommonUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @desc  数值型类型传感器统计数据
 * @author fwx 2024/2/28 11:46
 **/
@Data
public class PropertyNumCount {

    @ApiModelProperty(value = "最高值")
    private Double max;

    @ApiModelProperty(value = "最小值")
    private Double min;

    @ApiModelProperty(value = "平均值")
    private Double avg;

    @ApiModelProperty(value = "最高值时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime maxTime;

    @ApiModelProperty(value = "最低值时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime minTime;

    @ApiModelProperty(value = "去年同期最高值")
    private Double previousMax;

    @ApiModelProperty(value = "去年同期最小值")
    private Double previousMin;

    @ApiModelProperty(value = "去年同期平均值")
    private Double previousAvg;

    @ApiModelProperty(value = "去年最高值时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime previousMaxTime;

    @ApiModelProperty(value = "去年最低值时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime previousMinTime;
    
    @ApiModelProperty(value = "常年同期最高值")
    private Double beforeMax;

    @ApiModelProperty(value = "常年同期最小值")
    private Double beforeMin;

    @ApiModelProperty(value = "常年同期平均值")
    private Double beforeAvg;

    public void setBeforeMax(Double beforeMax) {
        if(beforeMax != null){
            beforeMax =  Math.round(beforeMax * 10) / 10.0;;
            this.beforeMax = beforeMax;
        }
    }

    public void setBeforeMin(Double beforeMin) {
        if(beforeMin != null){
            beforeMin =  Math.round(beforeMin * 10) / 10.0;;
            this.beforeMin = beforeMin;
        }
    }

    public void setBeforeAvg(Double beforeAvg) {
        if(beforeAvg != null){
            beforeAvg =  Math.round(beforeAvg * 10) / 10.0;;
            this.beforeAvg = beforeAvg;
        }
    }

    public void setPreviousCount(PropertyNumCount count){
        this.previousAvg = count.getAvg();
        this.previousMax = count.getMax();
        this.previousMin = count.getMin();
        this.previousMaxTime = count.getMaxTime();
        this.previousMinTime = count.getMinTime();
    }

    public void setBeforeCount(PropertyNumCount count){
        this.beforeAvg = count.getBeforeAvg();
        this.beforeMax = count.getBeforeMax();
        this.beforeMin = count.getBeforeMin();
    }
}
